package org.example.designPattern.creation.singleton;

import java.util.Arrays;

/**
* 匿名内部类——天然的懒汉单例
* */
public class SingletonDemo3 {

    private SingletonDemo3(){
        System.out.println("实例化！！！！！");
    }

    /* 内部静态类 */
    private static class Instance{
        private static final SingletonDemo3 singletonDemo3 = new SingletonDemo3();
    }

    /* 只有第一次被调用的时候才会被创建，所以是懒加载的升级版本 */
    public static SingletonDemo3 getInstance(){
        return Instance.singletonDemo3;
    }

    /*  */
    public static void main(String[] args) {
        System.out.println("args = " + Arrays.deepToString(args));
        SingletonDemo3.getInstance();
        SingletonDemo3.getInstance();
    }
}
